import { Toast, WingBlank } from "antd-mobile";
import React, { Component } from "react";
import LoginStatu from "./components/LoginStatu";
import Toolbar from "./components/Toolbar";
import { get } from "../../utils/Axios";

class PersonalPage extends Component {
  state = {
    isLogin: false,
    userInf: {},
  };

  componentDidMount() {
    const localToken = localStorage.getItem("xyzf_user_token");
    if (localToken) {
      setTimeout(() => {
        get("/user").then((result) => {
          if (result.data.status === 400) {
            this.setState({
              userInf: {},
            });
            Toast.info("登录超时", 3);
          } else if (result.data.status === 200) {
            this.setState({
              isLogin: true,
              userInf: result.data.body,
            });
          } else {
          }
        });
      }, 100);
    }
  }

  render() {
    const { isLogin } = this.state;
    const { userInf } = this.state;
    return (
      <div
        className="personalPageWrapper"
        style={{ height: "100%", width: "100%" }}
      >
        <LoginStatu isLogin={isLogin} userInf={userInf}></LoginStatu>
        <Toolbar></Toolbar>
        <WingBlank>
          <div style={{ height: "5px", backgroundColor: "#ecf0f1" }}></div>
        </WingBlank>
      </div>
    );
  }
}

export default PersonalPage;
